package jgl.vajra.operator.part.vehicle.activity;

import androidx.recyclerview.widget.LinearLayoutManager;

import java.util.ArrayList;
import java.util.List;

import jgl.vajra.operator.R;
import jgl.vajra.operator.databinding.ActivityConfirmOrderBinding;
import jgl.vajra.operator.dialogFragment.ModifyContactDialogFragment;
import jgl.vajra.operator.listener.MessageDlialogListener;
import jgl.vajra.operator.manager.FragmentManager;
import jgl.vajra.operator.manager.IntentManager;
import jgl.vajra.operator.part.home.pop.AccountingMethodPop;
import jgl.vajra.operator.part.vehicle.contract.ConfirmOrderContract;
import jgl.vajra.operator.part.vehicle.pop.FollowingCarPop;
import jgl.vajra.operator.part.vehicle.pop.IntegralSubtractionPop;
import jgl.vajra.operator.part.vehicle.pop.InvoicePop;
import jgl.vajra.operator.part.vehicle.viewModel.ConfirmOrderViewModel;
import jgl.vajra.operator.widget.databindingadapter.SingleTypeBindingAdapter;
import jgl.vajra.operator.widget.dialogfragment.MessageDialogFragment;
import jgl.vajra.operator.widget.mvvm.factory.CreateViewModel;
import jgl.vajra.operator.widget.mvvm.view.BaseMVVMActivity;
import jgl.vajra.operator.widget.utils.ToastUtils;

@CreateViewModel(ConfirmOrderViewModel.class)
public class ConfirmOrderActivity extends BaseMVVMActivity<ConfirmOrderViewModel, ActivityConfirmOrderBinding> implements ConfirmOrderContract.View {

    private FollowingCarPop followingCarPop;
    private ModifyContactDialogFragment modifyContactDialogFragment;
    private AccountingMethodPop accountingMethodPop;
    private MessageDialogFragment messageDialogAdditional;
    private InvoicePop invoicePop;
    private IntegralSubtractionPop integralSubtractionPop;

    @Override
    public int getLayoutId() {
        return R.layout.activity_confirm_order;
    }

    @Override
    public void initView() {
        super.initView();
        mBinding.setView(this);

        List<String> list = new ArrayList<>();
        list.add("");
        list.add("");
        list.add("");

        // 不可嵌套滑动
        mBinding.addressRecyclerView.setNestedScrollingEnabled(false);
        // 取消head 的 recycleView的焦点
        mBinding.addressRecyclerView.setFocusableInTouchMode(false);
        //设置布局管理器
        mBinding.addressRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        SingleTypeBindingAdapter addressAdapter = new SingleTypeBindingAdapter(this, list, R.layout.item_address_confirm_order);
        mBinding.addressRecyclerView.setAdapter(addressAdapter);
    }

    //修改联系人
    @Override
    public void onModifyContact() {
        if (modifyContactDialogFragment == null)
            modifyContactDialogFragment = new ModifyContactDialogFragment();
        modifyContactDialogFragment.show(getSupportFragmentManager());
    }

    //跟车
    @Override
    public void onFollowingCar() {
        if (followingCarPop == null) {
            followingCarPop = new FollowingCarPop(this);
        }
        followingCarPop.showPopupWindow(mBinding.getRoot());
    }

    //干活时长
    @Override
    public void onTime() {
        if (accountingMethodPop == null)
            accountingMethodPop = new AccountingMethodPop(this);
        accountingMethodPop.showPopupWindow(mBinding.getRoot());
    }

    //选择收藏基佬
    @Override
    public void onDriver() {
        IntentManager.toDriverCollectionActivity(this);
    }

    //增加司索工
    @Override
    public void onAdditional() {
        if (messageDialogAdditional == null) {
            messageDialogAdditional = FragmentManager.getMessageDialogAdditional(new MessageDlialogListener() {
                @Override
                public void onRightClick() {
                    ToastUtils.showShort("需要");
                }

                @Override
                public void onLeftClick() {
                    ToastUtils.showShort("不需要");
                }
            });
        }
        messageDialogAdditional.show(getSupportFragmentManager());
    }

    //单子备注
    @Override
    public void onOrderRemarks() {
        IntentManager.toOrderRemarksActivity(this);
    }

    //优惠券
    @Override
    public void onCoupon() {
//       IntentManager.toCouponPageActivity(this);
        //选择可使用的优惠券
       IntentManager.toCouponAvailableActivity(this);
    }

    //积分立减
    @Override
    public void onIntegralSubtraction() {
        if (integralSubtractionPop == null)
            integralSubtractionPop = new IntegralSubtractionPop(this);
        integralSubtractionPop.showPopupWindow(mBinding.getRoot());
    }

    //算账明细
    @Override
    public void onAccountingDetails() {
       IntentManager.toPricingRulesActivity(this);
    }

    //算算账
    @Override
    public void onCalculateAccounts() {
        IntentManager.toCalculateAccountsActivity(this);
    }

    //发票
    @Override
    public void onInvoice() {
        if (invoicePop == null)
            invoicePop = new InvoicePop(this);
        invoicePop.showPopupWindow(mBinding.getRoot());
    }

    //确定
    @Override
    public void onDetermine() {
        //等待接单
        IntentManager.toWaitingOrderActivity(this);
    }
}
